<?php
/**
 * Zend Framework Contribution
 *
 * LICENSE
 *
 * This source file is subject to the new BSD license that is bundled
 * with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://framework.zend.com/license/new-bsd
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@zend.com so we can send you a copy immediately.
 *
 * @category   Zend
 * @package    Zend_Mwb
 * @copyright  Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 * @version    1.0 PhysicalModels.php 3 mai 2012 Sergio DE VASCONCELOS
 */

require_once('Zend/Mwb/Dom/Abstract.php');
require_once('Zend/Mwb/Dom/Catalog.php');

/**
 * MySQL Workbench document
 *
 * @category   Zend
 * @package    Zend_Mwb
 */
class Zend_Mwb_Dom_PhysicalModels extends Zend_Mwb_Dom_Abstract
{
	/**
	 * @var Zend_Mwb_Dom_Catalog
	 */
	protected $catalog;
	/**
	 * @var Zend_Mwb_Dom_Diagrams
	 */
	protected $diagrams;
	
	/**
	 * return Zend_Mwb_Dom_Catalog
	 */
	public function getCatalog() {
		return $this->catalog;
	}
	/**
	 * @param Zend_Mwb_Dom_Catalog
	 * @return Zend_Mwb_Dom_PhysicalModels
	 */
	public function setCatalog($catalog) {
		$this->catalog = $catalog;
		return $this;
	}
	/**
	 * @return Zend_Mwb_Dom_Diagrams
	 */
	public function getDiagrams() {
		if (is_null($this->diagrams)) {
			$this->diagrams = $this->loadDiagrams();
		}
		return $this->diagrams;
	}
	/**
	 * @param Zend_Mwb_Dom_Diagrams
	 * @return Zend_Mwb_Dom_PhysicalModels
	 */
	public function setDiagrams($diagrams) {
		$this->diagrams = $diagrams;
		return $this;
	}
	
	protected function parse() {
		$dom = $this->node;// DOMElement

		$xpath = new DOMXPath($dom->ownerDocument);
    	$element = $xpath->query("value[@key='catalog']", $dom)->item(0);
        if (isset($element)) {
        	// FIXME : unset($this->catalog) 
        	$this->catalog = new Zend_Mwb_Dom_Catalog($element, $this);
        }
	}
	protected function loadDiagrams() {
		$xpath = new DOMXPath($this->node->ownerDocument);
    	$elements = $xpath->query("value[@key='diagrams']/value", $this->node);
		return new Zend_Mwb_Dom_Diagrams($elements, $this);
	}
}
